//mySort.h
#ifndef MYSORT_H_
#define MYSORT_H_
#include <iostream>
#include <cmath>
using namespace std;

template <typename T,class BinaryFunc>
void my_sort(T *a, int n, BinaryFunc bf) {
    (*bf)(a, n);
}

template <typename T>
void sortByDesc(T *a, int n) {
    for (int i = n - 1; i > 0; i--) {//降序
        for (int j = 0; j < i; j++) {
            if(a[j] < a[j + 1]) {
                T t = a[j];
                a[j] = a[j + 1];
                a[j + 1] = t;
            }
        }
    }
}

template <typename T>
void sortByAsce(T *a, int n) {//升序
    for (int i = n - 1; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            if(a[j] > a[j + 1]) {
                T t = a[j];
                a[j] = a[j + 1];
                a[j + 1] = t;
            }
        }
    }
}

template <typename T>
void sortByAbsAsce(T *a, int n) {//按绝对值升序
    for (int i = n - 1; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            if(abs(a[j]) > abs(a[j + 1])) {
                T t = a[j];
                a[j] = a[j + 1];
                a[j + 1] = t;
            }
        }
    }
}

template <typename T>
void sortByAbsDesc(T *a, int n) {//按绝对值降序
    for (int i = n - 1; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            if(abs(a[j]) < abs(a[j + 1])) {
                T t = a[j];
                a[j] = a[j + 1];
                a[j + 1] = t;
            }
        }
    }
}

template <typename T>
void printArray(T* t, int length) {
    cout << "[";
    for (int i = 0; i < length; i++) {
        if (i != length - 1) {
            cout << t[i] << ", ";
        } else {
            cout << t[i];
        }
    }
    cout << "]" << endl;
}
#endif